(function(){


window.onload = function () {
var u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
// document.getElementById("download1").href="http://fileserver.hisunhorse.com/xiaomalinjia2.apk"
// document.getElementById("download2").href="http://fileserver.hisunhorse.com/xiaomalinjia2.apk"
//alert("azsj");
// window.location.href = "mobile/index.html";
} else if (u.indexOf('iPhone') > -1) {//苹果手机
// document.getElementById("download1").href="https://itunes.apple.com/cn/app/xiao-ma-lin-jia/id1029054581?mt=8"
// document.getElementById("download2").href="https://itunes.apple.com/cn/app/xiao-ma-lin-jia/id1029054581?mt=8"
// window.location.href = "mobile/index.html";
//alert("pgsj");
} else if (u.indexOf('Windows Phone') > -1) {//winphone手机
alert("WP版暂未开发!");
// window.location.href = "mobile/index.html";
}
}



var now = { row:1, col:1 }, last = { row:0, col:0};
const towards = { up:1, right:2, down:3, left:4};
var isAnimating = false;

s=window.innerHeight/500;
ss=250*(1-s);

$$('.wrapa').css('-webkit-transform','scale('+s+','+s+') translate(0px,-'+ss+'px)');

document.addEventListener('touchmove',function(event){
	event.preventDefault(); },false);

$$(document).swipeUp(function(){
	if (isAnimating) return;
	last.row = now.row;
	last.col = now.col;
	if (last.row != 8) { now.row = last.row+1; now.col = 1; pageMove(towards.up);}	
})

$$(document).swipeDown(function(){
	if (isAnimating) return;
	last.row = now.row;
	last.col = now.col;
	if (last.row!=1) { now.row = last.row-1; now.col = 1; pageMove(towards.down);}	
})

$$(document).swipeLeft(function(){
	if (isAnimating){
		return;
	}
	last.row = now.row;
	last.col = now.col;

	if(last.row == 2){
		now.row = last.row;
		now.col = now.col + 1;
		if(now.col > 3){now.col = 3;return false;}
		pageMove(towards.left);
	}	
})

$$(document).swipeRight(function(){
	if (isAnimating) return;
	last.row = now.row;
	last.col = now.col;
	if(last.row == 2){
		now.row = last.row;
		now.col = now.col - 1;
		if(now.col < 1){now.col = 1;return false;}
		pageMove(towards.right);
	}
})

function pageMove(tw){

	var lastPage = ".page-" + last.row + "-" + last.col,
		nowPage  = ".page-" + now.row + "-" + now.col;
	
	// 页面导入导致第一次刷新不了
	if($(nowPage).find("div").hasClass('hide') == false){
		$(nowPage).find("div").addClass('hide');
	}
	if($(nowPage).find("img").hasClass('hide') == false){
		$(nowPage).find("img").addClass('hide');
	}
	switch(tw) {
		case towards.up:
			outClass = 'pt-page-moveToTop';
			inClass = 'pt-page-moveFromBottom';
			break;
		case towards.right:
			outClass = 'pt-page-moveToRight';
			inClass  = 'pt-page-moveFromLeft';
			break;
		case towards.down:
			outClass = 'pt-page-moveToBottom';
			inClass = 'pt-page-moveFromTop';
			break;
		case towards.left:
			outClass = 'pt-page-moveToLeft';
			inClass = 'pt-page-moveFromRight';
			break;
	}
	isAnimating = true;
	$$(nowPage).removeClass("hide");
	
	$$(lastPage).addClass(outClass);
	$$(nowPage).addClass(inClass);

	setTimeout(function(){
		$$(lastPage).removeClass('page-current');
		$$(lastPage).removeClass(outClass);
		$$(lastPage).addClass("hide");
		$$(lastPage).find("div").addClass("hide");
		$$(lastPage).find("img").addClass("hide");
		
		$$(nowPage).addClass('page-current');
		$$(nowPage).removeClass(inClass);
		$$(nowPage).find("div").removeClass("hide");
		$$(nowPage).find("img").removeClass("hide");
		
		isAnimating = false;
	},600);
}

})();